package com.sunlgggg.view.component;

import com.google.gson.Gson;
import com.sunlgggg.object.StudentInfo;
import org.jdesktop.swingx.JXDatePicker;

import javax.swing.*;
import java.awt.*;
import java.util.Date;

import static com.sunlgggg.util.HttpRequestUtils.*;

/**
 * Created by sunlggggg on 2016/12/1.
 */
public class ManagerOperation extends JPanel {
    //JLabel组
    JLabel stuIdJLabel;
    JLabel nameJLabel;
    JLabel genderJLabel;
    JLabel bornDateJLabel;
    JLabel chineseJLabel;
    JLabel mathJLabel;
    JLabel englishJLabel;

    //TextView
    public JTextField stuIdJTextField;
    public JTextField nameJTextField;
    public JTextField genderJTextField;
    public JXDatePicker bornDateJTextField;
    public JTextField chineseJTextField;
    public JTextField mathJTextField;
    public JTextField englishJTextField;

    //按钮组
    public JButton addStudentButton;
    public JButton modifyStudentButton;
    public JButton deleteStudentButton;

    public ManagerOperation() {
        this.setLayout(new BorderLayout());
        JPanel info = new JPanel();
        info.setLayout(new GridLayout());
        info.setPreferredSize(new Dimension(650, 25));
//        info.setBorder(BorderFactory.createLineBorder(Color.black, 5));


        JPanel buttons = new JPanel();
        stuIdJLabel = new JLabel("学号：");
        nameJLabel = new JLabel("姓名：");
        genderJLabel = new JLabel("性别：");
        bornDateJLabel = new JLabel("出生日期：");
        chineseJLabel = new JLabel("语文：");
        mathJLabel = new JLabel("数学：");
        englishJLabel = new JLabel("英语：");

        stuIdJTextField = new JTextField("     ");
        nameJTextField = new JTextField("      ");
        genderJTextField = new JTextField("     ");
        bornDateJTextField = new JXDatePicker();
        chineseJTextField = new JTextField("      ");
        mathJTextField = new JTextField("      ");
        englishJTextField = new JTextField("     ");

        info.add(stuIdJLabel, BorderLayout.EAST);
        info.add(stuIdJTextField, BorderLayout.EAST);
        info.add(nameJLabel, BorderLayout.EAST);
        info.add(nameJTextField, BorderLayout.EAST);
        info.add(genderJLabel, BorderLayout.EAST);
        info.add(genderJTextField, BorderLayout.EAST);
        info.add(bornDateJLabel, BorderLayout.EAST);
        info.add(bornDateJTextField, BorderLayout.EAST);
        info.add(chineseJLabel, BorderLayout.EAST);
        info.add(chineseJTextField, BorderLayout.EAST);
        info.add(mathJLabel, BorderLayout.EAST);
        info.add(mathJTextField, BorderLayout.EAST);
        info.add(englishJLabel, BorderLayout.EAST);
        info.add(englishJTextField, BorderLayout.EAST);

        addStudentButton = new JButton("添加");

        modifyStudentButton = new JButton("修改");

        deleteStudentButton = new JButton("删除");


        buttons.add(addStudentButton, BorderLayout.EAST);
        buttons.add(modifyStudentButton, BorderLayout.EAST);
        buttons.add(deleteStudentButton, BorderLayout.EAST);
        this.add(info, BorderLayout.NORTH);
        this.add(buttons, BorderLayout.SOUTH);
    }

    public static void main(String[] args) {
        StudentInfo studentInfo = new StudentInfo();
        studentInfo.setStuId("ccc");
        studentInfo.setGender("g");
        studentInfo.setName("121");
        studentInfo.setBornDate(new Date());
        studentInfo.setChineseScore(Double.valueOf("12"));
        studentInfo.setMathScore(Double.valueOf("12"));
        studentInfo.setEnglishScore(Double.valueOf("13"));
        post("info/addInfo", "studentinfo=" + new Gson().toJson(studentInfo));
    }
}
